﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "spin.h"

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos
{

    spin::spin()
    {
        //pthread_spin_init( &m_spin, PTHREAD_PROCESS_PRIVATE );
        pthread_mutex_init( &m_mutex, 0 );
    }

    spin::~spin()
    {
        //pthread_spin_destroy( &m_spin );
        pthread_mutex_destroy( &m_mutex );
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // method

    int spin::un_lock()
    {
        int nRet = 0;
        //pthread_spin_unlock( &m_spin );
        pthread_mutex_unlock( &m_mutex );
        return nRet;
    }

    int spin::lock()
    {
        int nRet = 0;
        //pthread_spin_lock( &m_spin );
        pthread_mutex_lock( &m_mutex );
        return nRet;
    }

} // xos
